package com.jane.adapter.homepageadapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.jane.bean.HomePageGridViewBean;
import com.jane.definedview.GridViewWithHeaderAndFooter;
import com.jane.gzzb.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/11/15.
 */

public class MeAttentionAdapter extends BaseAdapter {
    //申明
    private Context mContext;
    private LayoutInflater mInflater;
    private List<List<HomePageGridViewBean>> lists;

    public MeAttentionAdapter(Context context, List<List<HomePageGridViewBean>> lists) {
        mContext = context;
        this.lists = lists;
        mInflater = LayoutInflater.from(mContext);
    }

    @Override
    public int getCount() {
        return lists == null ? 0 : lists.size();
    }

    @Override
    public Object getItem(int position) {
        return lists.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_list_meattention, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        //获取数据
        List<HomePageGridViewBean> data = (List<HomePageGridViewBean>) getItem(position);
        if (position == 0) {
            holder.title.setText("直播中");
            YesLiveAdapter yesAdapter = new YesLiveAdapter(mContext, new ArrayList());
            yesAdapter.addData(data);
            holder.listView.setAdapter(yesAdapter);
        } else if (position == 1) {
            holder.title.setText("未开播");
            NotLiveAdapter notAdapter = new NotLiveAdapter(mContext, new ArrayList());
            notAdapter.addData(data);
            holder.listView.setAdapter(notAdapter);
        }
        return convertView;
    }

    public static class ViewHolder {
        TextView title;
        GridViewWithHeaderAndFooter listView;

        public ViewHolder(View convertView) {
            title = (TextView) convertView.findViewById(R.id.item_list_meattention_title);
            listView = (GridViewWithHeaderAndFooter) convertView.findViewById(R.id.item_list_meattention_lsitview);
        }
    }
}
